package com.ellecity06.debugtools.ui.request_details

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.cachedIn
import com.ellecity06.debugtools.base.BaseDebugViewModel
import com.ellecity06.debugtools.db.dao.RequestDao
import com.ellecity06.debugtools.db.entity.RequestEntity
import com.ellecity06.debugtools.ui.fragment.request.pagination.DebugRequestPagingSource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch

/**
 * @author ellecity06
 * @time 2023/4/21 11:43
 * @des
 */
internal class DebugRequestDetailViewModel(private val dao: RequestDao, private val id: Int) : BaseDebugViewModel() {

    val data = Pager(PagingConfig(pageSize = 10, enablePlaceholders = false, initialLoadSize = 10)) {
        DebugRequestDetailSource(dao, id)
    }.flow.cachedIn(viewModelScope)

}

internal class DaoViewModelFactory(
    private val create: () -> ViewModel
) : ViewModelProvider.Factory {
    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        return create.invoke() as T

    }

}